package com.sp.controller;

import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import com.sp.util.R;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * test_biz
 *
 * @author jizhaojian
 * @date 2025-08-04 10:17:05
 */
@RestController
@RequestMapping("/test_biz" )
public class TestController {
    @GetMapping("/test02" )
    public R test02() {
        return R.ok();
    }

    @GetMapping("/test01" )
    public R test01() {
        String arrStr ="""
JVGLOTC0097064502	,
JVGLOTC0092031659	,

                """;
        arrStr =arrStr.replace("\n", "").replace("\t", "");
        List<String> listId = List.of(arrStr.split(","));
        listId.forEach(id -> {
            String result = postFun(id);
            System.out.println(result);
        });

        return R.ok();
    }

    public String postFun(String id) {
        String url = "http://api.il.u-speed.net/packageReceiveSubmit/submit";
        String authorization ="Bearer 066f5b4d0f624ecc912a0b89204e2040";
        String json ="""
                    {
                        "packageNumber": "?",
                        "container1": "AE-Reoperation-sys",
                        "container2": "AE-Reoperation-sys",
                        "container3": "AE-Reoperation-sys"
                    }
                """;

         json = json.replace("?", id);
        // HttpUtil.createPost 创建POST请求，加authorization
        HttpResponse response = HttpUtil.createPost(url)
                .header("Authorization", authorization)
                .body(json)
                .execute();
        String result =response.body();
        return "id:"+id+"  result:"+result;
    }

}
